<?php
$full = elgg_extract ( 'full_view', $vars, FALSE );
$show_submitlink = elgg_extract ( 'submitlink', $vars, FALSE );
$assignment = elgg_extract ( 'entity', $vars, FALSE );

$deadline_str = $assignment->deadline;

$deadline_date_str = explode ( "/", $deadline_str );
$deadline = mktime(23, 59, 0,$deadline_date_str[1], $deadline_date_str[0], $deadline_date_str[2]);
$now = strtotime("now");

$base_url = elgg_get_site_url() . "submana";
if (! $assignment->file_url) {
	$project = get_entity ( $assignment->container_guid );
	if ($project) {
		$submit_url = elgg_get_site_url () . "submana/project/$project->container_guid/submitasg/{$assignment->getGUID()}";
	}
	if ($show_submitlink && $now < $deadline) {
		$submit_link = elgg_view ( 'output/url', array (
				'href' => $submit_url,
				'text' => elgg_echo ( 'submana:submit' ),
				'class' => "assignment_normal",
				'is_action' => true,
				'is_trusted' => true 
		) );
	}
	
	if ($deadline < $now) {
		$class = "deadlined";
	} else if ($now > ($deadline - 48 * 60 * 60)) {
		$class = "deadlining";
	}
} else {
	$submitedfile_link = elgg_view ( 'output/url', array (
			'href' => $assignment->file_url,
			'text' => elgg_echo ( 'submana:submitedfile' ),
			'class' => "assignment_normal",
			'is_action' => false,
			'is_trusted' => false 
	) );
	if ($show_submitlink && $now < $deadline) {
		$project = get_entity ( $assignment->container_guid );
		if ($project) {
			$submit_url = elgg_get_site_url () . "submana/project/$project->container_guid/submitasg/{$assignment->getGUID()}";
		}
		$submit_link = elgg_view ( 'output/url', array (
				'href' => $submit_url,
				'text' => elgg_echo ( 'submana:editsubmit' ),
				'class' => "assignment_normal",
				'is_action' => true,
				'is_trusted' => true 
		) );
	}
}

if ($full) {
	$description = elgg_view ( 'output/longtext', array (
			'value' => $assignment->description 
	) );
	$note_html = "<div class='clearboth'></div><div style=''> $description </div>";
	$class .= " fullview";
	// edit and delete link
	if ($assignment->canEdit (elgg_get_logged_in_user_guid())) {
		$project = get_entity($assignment->container_guid);
	
		$del_url = "$base_url/assign/del/{$assignment->getGUID()}/{$project->getContainerGUID()}";
		$del_url = elgg_add_action_tokens_to_url ( $del_url );
		$del_confirm = elgg_echo ( 'submana:delete' );
	
		$edit_url = "$base_url/assign/edit/{$assignment->getGUID()}/{$project->getContainerGUID()}";
		$edit_url = elgg_add_action_tokens_to_url ( $edit_url );
		$edit_label = elgg_echo ( 'submana:edit' );
	
		$edit_del_url = "<div class='right'>
		<ul	class='elgg-menu elgg-menu-entity elgg-menu-hz elgg-menu-entity-default'>
		<li class='elgg-menu-item-edit'><a href='$edit_url'>$edit_label</a></li>
		<li class='elgg-menu-item-delete'><a href='$del_url'
		rel='$del_confirm'
		class='elgg-requires-confirmation'><span
		class='elgg-icon elgg-icon-delete '></span></a></li>
		</ul>
		</div>";
	}
} else {
	$class .= " smallview";
}

echo <<<___HTML
<div class="assignment $class">
	$edit_del_url
	<div>
	
	</div>
	<div class="left">
		<a href="{$assignment->getURL()}">$assignment->title</a>
		&nbsp &nbsp <span style="color:red;">$deadline_str</span>
		&nbsp &nbsp $submitedfile_link
	</div>
	<div class="right">
		&nbsp &nbsp $submit_link
	</div>
	$note_html
</div>
	
___HTML;

?>